package group.sicher.core.exception;


import group.sicher.core.exception.base.BaseException;
import group.sicher.core.exception.base.ErrorCode;
import group.sicher.core.exception.base.SicherErrorCode;
import group.sicher.core.web.response.SicherResponse;

/**
 * 框架控制器返回统一异常
 */
public class ResponseException extends BaseException {

    private int httpStatus = 200;
    private ErrorCode code;   //错误类型编号
    private Object data;    //错误携带数据

    public ResponseException(ErrorCode code) {
        super(code.desc());
        this.code = code;
    }

    public ResponseException(String message) {
        super(message);
        this.code = SicherErrorCode.DEFAULT_ERROR;
    }

    public ResponseException(String message, Object data) {
        super(message);
        this.code = SicherErrorCode.DEFAULT_ERROR;
        this.data = data;
    }

    public ResponseException(String message, Object data, Throwable cause) {
        super(message, cause);
        this.code = SicherErrorCode.DEFAULT_ERROR;
        this.data = data;
    }

    public ResponseException(String message, Throwable cause) {
        super(message, cause);
        this.code = SicherErrorCode.DEFAULT_ERROR;
    }


    public ResponseException(Object data) {
        super(SicherErrorCode.DEFAULT_ERROR.desc());
        this.data = data;
        this.code = SicherErrorCode.DEFAULT_ERROR;
    }

    public ResponseException(ErrorCode code, String message) {
        super(message);
        this.code = code;
    }

    public ResponseException(ErrorCode code, String message, Object data) {
        super(message);
        this.code = code;
        this.data = data;
    }

    public ResponseException(ErrorCode code, String message, Object data, Throwable cause) {
        super(message, cause);
        this.code = code;
        this.data = data;
    }

    public ResponseException(ErrorCode code, String message, Throwable cause) {
        super(message, cause);
        this.code = code;
    }

    public ResponseException(ErrorCode code, Object data) {
        super(code.desc());
        this.data = data;
        this.code = code;
    }

    public int getHttpStatus() {
        return httpStatus;
    }

    public void setHttpStatus(int httpStatus) {
        this.httpStatus = httpStatus;
    }

    public ErrorCode getCode() {
        return code;
    }

    public void setCode(ErrorCode code) {
        this.code = code;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    public SicherResponse transferResponse() {
        SicherResponse response = new SicherResponse(this.code.code());
        response.setErrMsg(this.getMessage());
        return response;
    }
}
